package com.example.sendmassege.thread;

/**
 * @Author wxc
 * @Date 2021/4/30 14:30
 *
 * 多个线程操作同一个资源，会出现资源使用问题
 */
public class DemoThread implements Runnable {

    private int tickets=10;
    @Override
    public void run() {

        while (true){
            if (tickets<0){
                break;
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"-->拿到了"+tickets--+"张票！");
        }
    }

    public static void main(String[] args) {
        DemoThread demoThread = new DemoThread();
        new Thread(demoThread,"张三").start();
        new Thread(demoThread,"李四").start();
        new Thread(demoThread,"王五").start();
    }
}
